import QtQuick 2.9
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.0

Window {
    objectName: "solidWindow"
    id: solidWindow
    width: w + 2
    height: h + 40 + 2
    visible: true

    property int w: 200
    property int h: 200

    flags: Qt.Window | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint

    onVisibleChanged: {
        if (w < 200) {
            w = 200
        }
        if (h < 200) {
            h = 200
        }
    }

    // 自定义标题栏
    Rectangle {
        id: titleBar
        height: 40
        color: "#252526"
        anchors {
            top: parent.top
            left: parent.left
            right: parent.right
        }

        Item {
            width: 39
            height: 24
            anchors.verticalCenter: parent.verticalCenter
            Image {
                source: "qrc:/image/res/screenshot.png"
                anchors.fill: parent
                anchors.leftMargin: 15
            }
        }

        // 标题文本
        Text {
            text: "截图预览"
            color: "white"
            font.pixelSize: 16
            anchors.verticalCenter: parent.verticalCenter
            leftPadding: 54
        }

        // 关闭按钮
        Button {
            id: closeButton
            width: 40
            height: 40
            anchors.right: parent.right
            background: Rectangle {
                color: closeButton.hovered ? "#E81123" : "transparent"
                Image {
                    source: "qrc:/image/res/close_0.png"  // 自定义关闭图标
                    anchors.centerIn: parent
                    width: 16; height: 16
                }
            }
            onClicked: solidWindow.close()
            ToolTip {
                visible: parent.hovered
                text: "关闭"
                delay: 500
            }
        }

        // 窗口拖动区域
        MouseArea {
            anchors.fill: parent
            anchors.rightMargin: 40
            property point startPos: "0,0"
            onPressed: startPos = Qt.point(mouseX, mouseY)
            onPositionChanged: {
                if (pressed) {
                    var delta = Qt.point(mouseX - startPos.x, mouseY - startPos.y)
                    solidWindow.x += delta.x
                    solidWindow.y += delta.y
                }
            }
        }
    }

    Rectangle {
        border.width: 1
        border.color: "#515151"
        anchors.fill: parent
        anchors.topMargin: 39
        Image {
            source: "image://pixmap/shot?stamp=" + new Date()
            id: screenshotImage
            anchors.fill: parent
            anchors.margins: 1
            fillMode: Image.PreserveAspectFit // 保持纵横比自适应缩放
            anchors.centerIn: parent // 图片居中显示
        }
    }
}
